package com.example.arcapplication.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.arcapplication.bean.StockList;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "STOCK_LIST".
*/
public class StockListDao extends AbstractDao<StockList, Void> {

    public static final String TABLENAME = "STOCK_LIST";

    /**
     * Properties of entity StockList.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Sid = new Property(0, Long.class, "sid", false, "SID");
        public final static Property Stockid = new Property(1, String.class, "stockid", false, "STOCKID");
        public final static Property Stockname = new Property(2, String.class, "stockname", false, "STOCKNAME");
    }

    private Query<StockList> inventory_StockListQuery;

    public StockListDao(DaoConfig config) {
        super(config);
    }
    
    public StockListDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"STOCK_LIST\" (" + //
                "\"SID\" INTEGER," + // 0: sid
                "\"STOCKID\" TEXT," + // 1: stockid
                "\"STOCKNAME\" TEXT);"); // 2: stockname
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"STOCK_LIST\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, StockList entity) {
        stmt.clearBindings();
 
        Long sid = entity.getSid();
        if (sid != null) {
            stmt.bindLong(1, sid);
        }
 
        String stockid = entity.getStockid();
        if (stockid != null) {
            stmt.bindString(2, stockid);
        }
 
        String stockname = entity.getStockname();
        if (stockname != null) {
            stmt.bindString(3, stockname);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, StockList entity) {
        stmt.clearBindings();
 
        Long sid = entity.getSid();
        if (sid != null) {
            stmt.bindLong(1, sid);
        }
 
        String stockid = entity.getStockid();
        if (stockid != null) {
            stmt.bindString(2, stockid);
        }
 
        String stockname = entity.getStockname();
        if (stockname != null) {
            stmt.bindString(3, stockname);
        }
    }

    @Override
    public Void readKey(Cursor cursor, int offset) {
        return null;
    }    

    @Override
    public StockList readEntity(Cursor cursor, int offset) {
        StockList entity = new StockList( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // sid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // stockid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // stockname
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, StockList entity, int offset) {
        entity.setSid(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setStockid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setStockname(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final Void updateKeyAfterInsert(StockList entity, long rowId) {
        // Unsupported or missing PK type
        return null;
    }
    
    @Override
    public Void getKey(StockList entity) {
        return null;
    }

    @Override
    public boolean hasKey(StockList entity) {
        // TODO
        return false;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "stockList" to-many relationship of Inventory. */
    public List<StockList> _queryInventory_StockList(Long sid) {
        synchronized (this) {
            if (inventory_StockListQuery == null) {
                QueryBuilder<StockList> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Sid.eq(null));
                inventory_StockListQuery = queryBuilder.build();
            }
        }
        Query<StockList> query = inventory_StockListQuery.forCurrentThread();
        query.setParameter(0, sid);
        return query.list();
    }

}
